import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  //首页路由
  {
    path: '/',
    name: 'Index',
    component: () => import('../views/Index.vue')
  },
  //登录页
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  // 布局页面
  {
    path: '/layout',
    name: 'layout',
    component: () => import('../views/layout.vue'),
    children: [
      {
        path: 'finance',
        name: 'finance',
        component: () => import('../views/finance/finance.vue')
      },
      {
        path: 'groupList',
        name: 'groupList',
        component: () => import('../views/finance/groupList.vue')
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('../views/role/role.vue')
      },
      {
        path: 'dictionary',
        name: 'dictionary',
        component: () => import('../views/dictionary/dictionary.vue')
      }
      ,
      {
        path: 'introspection',
        name: 'introspection',
        component: () => import('../views/introspection/introspection.vue')
      }
    ]
  }

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

//导入nprogress
import NProgress from 'nprogress'
//导入nprogress的样式
import 'nprogress/nprogress.css'

//定义路由前置守卫
router.beforeEach((to, from, next) => {
  NProgress.start();
  next()
})

//定义路由后置守卫
router.afterEach((to, from, failure) => {
  NProgress.done()
})

export default router
